#!/bin/sh
#
# kill-lang - automatically remove all non-english locale files
# this is meant to run before find-lang.sh in order to remove the
# locale files with a quick call and still keep the %find_lang macro
# intact
#
# copyright (c) 2006 Vincent Danen <vdanen@annvix.org>
#
# Redistribution and use of this software are hereby permitted for any
# purpose as long as this notice and the above copyright notice remain
# in tact and are included with any redistribution of this file or any
# work based on this file.
#
# $Id$

usage() {
cat <<EOF

Usage: ${0} TOP_DIR PACKAGE_NAME

where TOP_DIR is
the top of the tree containing the files to be processed--should be
\$RPM_BUILD_ROOT usually. TOP_DIR gets sed'd out of the output list.
PACKAGE_NAME is the %{name} of the package. This should also be  
the basename of the .mo files.
EOF
exit 1
}

args=$*

if [ -z "${1}" ]; then usage
elif [ "${1}" = "/" ]; then echo ${0}: expects non-/ argument for '${1}' 1>&2
elif [ ! -d ${1} ]; then
    echo ${0}: ${1}: no such directory
    exit 1
else TOP_DIR="`echo ${1}|sed -s 's:/$::'`"
fi
shift

if [ -z "${1}" ]; then usage
else NAME=${1}
fi
shift

dirlist="usr/share/locale usr/share/man usr/local/share/locale usr/local/share/man"
for x in ${dirlist}
do
    process="`find ${TOP_DIR}/${x}/* -type d 2>/dev/null|egrep -v 'man[0-9]'`"
    for i in ${process}
    do
        if [ "`echo ${i}|egrep '/en' >/dev/null 2>&1; echo $?`" == "1" ]; then
            rm -rf ${i} >/dev/null 2>&1
        fi
    done
done